package com.stone.compose.ui.screen.login

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.stone.compose.route.RouteName
import com.stone.compose.vm.LoginViewModel

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoginScreen(navController: NavController,   loginViewModel: LoginViewModel = viewModel()) {



    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp)
        ,
        verticalArrangement= Arrangement.Center
    ) {
        Card(
            modifier = Modifier
        ) {


            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(16.dp)
            ) {

                TextField(
                    value = loginViewModel.uiState.username,
                    onValueChange = {
                        Log.i("sss", "LoginScreen11: $it")
                        loginViewModel.uiState.username = it
                    },
                    label = {
                        Text(text = "用户名")
                    }
                )

                Spacer(modifier = Modifier.height(20.dp))

                TextField(
                    value = loginViewModel.uiState.password,
                    onValueChange = {
                        Log.i("sss", "LoginScreen22: $it")
                        loginViewModel.uiState.password = it
                    },
                    label = {
                        Text(text = "密码")
                    }
                )

                Spacer(modifier = Modifier.height(20.dp))

                Button(
                    onClick = {
//                        loginViewModel.login()
                        navController.navigate(RouteName.MESSAGE)
                    },
                    shape = RoundedCornerShape(10.dp),
                    modifier = Modifier.fillMaxWidth()
                ) {
                    Text(text = "登录")
                }
            }

        }

    }


}




